import numpy as np
import os
import pandas as pd
from sklearn.neural_network import MLPClassifier


##运行脚本所在目录
base_dir=os.getcwd()
##记得添加header=None,否则会把第一行当作头
data=pd.read_table(base_dir+r"\wine.txt",header=None,sep=';')
##dataLen行dataWid列 ：返回值是dataLen=1599 dataWid=12
dataLen,dataWid = data.shape

##训练数据集
xList = []
##标签数据集
lables = []
##读取数据
for i in range(dataLen):
    row = data.values[i]
    xList.append(row[0:dataWid-1])
    lables.append(row[-1])
##设置训练函数
clf = MLPClassifier(solver='lbfgs', alpha=1e-5,
                        hidden_layer_sizes=(14,14,30), random_state=1)
##开始训练数据
clf.fit(xList, lables)
##读取预测值
y_pred=clf.predict(xList)
m = len(y_pred)

t = 0
f = 0
##预测结果分析
for i in range(m):
    if int(y_pred[i]) == lables[i]:
        t += 1
    else :
        f += 1
print("正确:"+str(t))
print("错误:"+str(f))